fontlist = new item(50);
fontclose = new item(50);
anchorlist = new item(50);
textarealist = new item(20);

function item(pos, font, face, size, color)
{
        this.pos = pos;
		this.font = font;
        this.face = face;
		this.size = size;
        this.color = color;
}


function ClipBoard() 
{
	Copied = document.fm.textbox.createTextRange();
	Copied.execCommand("Copy");
	document.fm.textbox.select();
}	// end functuon ClipBoard()

function do_font(fonttext)
{
	var i = 0;
	var j = 0;
	var n;
	var pos;
	var subfonttext;	
		
	fonttext = fonttext.toUpperCase();
	//document.fm.textbox.value = fonttext;
	
	for (pos = 0; pos != -1; pos)
	{
		pos = fonttext.indexOf("<FONT", pos);
		//document.fm.textbox.value = document.fm.textbox.value + pos;
		
		if (pos != -1)  // if <FONT is found
		{
			n = fonttext.indexOf(">", pos);
		
			fontlist[i] = new item(0, 0, 0, 0, 0);
			fontlist[i].pos = pos;
			fontlist[i].font = 1;

			subfonttext = fonttext.substring(pos, n);
		
			if (subfonttext.search(/FACE/) != -1)
				fontlist[i].face = 1;
			else
				fontlist[i].face = 0;
		
			if (subfonttext.search(/SIZE/) != -1)
				fontlist[i].size = 1;
			else
				fontlist[i].size = 0;
		
			if (subfonttext.search(/COLOR/) != -1)
				fontlist[i].color = 1;
			else
				fontlist[i].color = 0;
			
			//document.fm.textbox.value = document.fm.textbox.value + i +
			//subfonttext + fontlist[i].font + fontlist[i].color + '.';
			
			pos++;
			i++;
			
		}  // end if <FONT is found
		//i--;  // so i equals the length of fontlist
	}  // end for
	

	// Now find all closing font tags </FONT>
	for (pos = 0; pos != -1; pos)
	{
		pos = fonttext.indexOf("</FONT>", pos++);
	
		//document.fm.textbox.value = document.fm.textbox.value + pos;
		if (pos != -1)  // if </FONT> found
		{
			//document.fm.textbox.value = document.fm.textbox.value + "i=" + i + ".";
			fontclose[j] = new item(0, 0, 0, 0, 0);
			fontclose[j].pos = pos;
			fontclose[j].font = 1;	
			for (ii = i-1; ii >= 0; ii--)
			{
				//document.fm.textbox.value = document.fm.textbox.value + "h1.";
				if (fontlist[ii].pos < pos)
				{	
					//document.fm.textbox.value = document.fm.textbox.value + "h2.";
					if (fontlist[ii].font == 1)
					{
						//document.fm.textbox.value = document.fm.textbox.value + "h3.";
						fontlist[ii].font = 0;
						fontclose[j].color = fontlist[ii].color;
						fontclose[j].size = fontlist[ii].size;
						fontclose[j].face = fontlist[ii].face;
						ii = -1;  // since we found it, exit for loop
					}  // end if opening FONT tag
				}  // end if			
			} // end for
			pos++;
			j++;
		}  // end if </FONT> found
		else
		{
			fontclose[j] = new item(0, 0, 0, 0, 0);
			fontclose[j].font = 0;
		}
		
	}  // end for	
	//for (i = 0;fontclose[i].font != 0; i++)
	//	{
	//		document.fm.textbox.value = document.fm.textbox.value +
	//			fontclose[i].font + fontclose[i].color +
	//			fontclose[i].size + fontclose[i].face;
	//	} 
	//alert("hi");
}  //  end function do_font()


function do_anchor(fonttext)
{
	var i = 0;
	var j = 0;
	var n;
	var pos;
	var subfonttext;	
		
	fonttext = fonttext.toUpperCase();
	//document.fm.textbox.value = fonttext;
	
	for (pos = 0; pos != -1; pos)
	{
		pos = fonttext.indexOf("<A HREF", pos);
		//document.fm.textbox.value = document.fm.textbox.value + pos;
		
		if (pos != -1)  // if <A HREF is found
		{
			n = fonttext.indexOf(">", pos);
		
			anchorlist[i] = new item(0, 0, 0, 0, 0);
			//fontlist[i].pos = pos;
			anchorlist[i].font = 1;

			subfonttext = fonttext.substring(pos, n);
		
			if (subfonttext.search(/MAILTO:/) != -1)
			{
				subfonttext = subfonttext.replace(/<A HREF=MAILTO:/, "");
				subfonttext = subfonttext.replace(/\"/, "");
				subfonttext = subfonttext.replace(/\'/, "");
				anchorlist[i].pos = 1; // mailto: flag
				subfonttext = subfonttext.toLowerCase();
				anchorlist[i].face = subfonttext; // email address
			}
			else
			{
				anchorlist[i].pos = 2; // http: flag
			}
			
			//document.fm.textbox.value = document.fm.textbox.value + i +
			//subfonttext + fontlist[i].font + fontlist[i].color + '.';
			
			pos++;
			i++;
			
		}  // end if <A HREF is found
		else
		{
			anchorlist[i] = new item(0, 0, 0, 0, 0);
			anchorlist[i].pos = 0; // no more anchors flag
		}	
		//i--;  // so i equals the length of fontlist
	}  // end for
	
}  //  end function do_anchor()


// this function copies all the textarea data to strings
// to preserve its code exactly as it is and not change it
function do_textarea(fonttext)
{
	var i = 0;
	var j = 0;
	var n;
	var pos;
	var subfonttext;	
		
	textareatext = fonttext;  // need this to preserve case
	fonttext = fonttext.toUpperCase();
	//document.fm.textbox.value = fonttext;
	
	for (pos = 0; pos != -1; pos)
	{
		pos = fonttext.indexOf("<TEXTAREA", pos);
		//document.fm.textbox.value = document.fm.textbox.value + pos;
		
		if (pos != -1)  // if <TEXTAREA is found
		{
			n = fonttext.indexOf(">", pos);
			pos = fonttext.indexOf("</TEXTAREA>", n);
			if (pos != -1) // if </TEXTAREA> is found
			{	
				textarealist[i] = new item(0, 0, 0, 0, 0);
				textarealist[i].face = textareatext.substring(n+1, pos);
				// notice that we copied the area from textareatext
				// because it has not had its case changed to upper
				//fontlist[i].pos = pos;
				textarealist[i].pos = 1;
			}
		
		
			
			//document.fm.textbox.value = document.fm.textbox.value + i +
			//subfonttext + fontlist[i].font + fontlist[i].color + '.';
			
			pos++;
			i++;
			
		}  // end if <TEXTAREA is found
		else
		{
			textarealist[i] = new item(0, 0, 0, 0, 0);
			textarealist[i].pos = 0; // no more textareas flag
		}	
		//i--;  // so i equals the length of fontlist
	}  // end for
	
}  //  end function do_textarea()


function convert(bbcodetext)
{		
	codetype = 'bbcode';
	do_font(bbcodetext);	
	do_textarea(bbcodetext);		
	
	// maybe they put spaces around the = .  Remove them
	bbcodetext = bbcodetext.replace(/ = /gi, "=");
	// maybe they put quotes surrounding the value
	// so look for =" and ">
	bbcodetext = bbcodetext.replace(/=\"/gi, "=");
	//bbcodetext = bbcodetext.replace(/\">/gi, ">");
	// maybe they put single quote surrounding the value
	// so look for =' and '>
	bbcodetext = bbcodetext.replace(/=\'/gi, "=");
	//bbcodetext = bbcodetext.replace(/\'>/gi, ">");	
	
	bbcodetext = bbcodetext.replace(/<param name=movie[^>]*value=/gi, "<movie=");
	
	bbcodetext = bbcodetext.replace(/ BORDER=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ BORDER=[^\'>]*\'/gi, " ");
	bbcodetext = bbcodetext.replace(/ TARGET=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ TARGET=[^\'>]*\'/gi, "");
	bbcodetext = bbcodetext.replace(/ CLASSID=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ CLASSID=[^\'>]*\'/gi, "");
	bbcodetext = bbcodetext.replace(/ ID=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ ID=[^\'>]*\'/gi, "");
	bbcodetext = bbcodetext.replace(/ NAME=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ NAME=[^\'>]*\'/gi, "");
	//bbcodetext = bbcodetext.replace(/ ALIGN=[^\"]*\"/gi, "");
	//bbcodetext = bbcodetext.replace(/ ALIGN=[^\']*\'/gi, "");
	//bbcodetext = bbcodetext.replace(/ ALIGN=[^>]*>/gi, ">");
	bbcodetext = bbcodetext.replace(/ STYLE=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ STYLE=[^\'>]*\'/gi, "");
	bbcodetext = bbcodetext.replace(/ CLASS=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ CLASS=[^\'>]*\'/gi, "");
	bbcodetext = bbcodetext.replace(/ ALT=[^\'\">]*[\'\">]/gi, "");
	//bbcodetext = bbcodetext.replace(/ ALT=[^\'>]*\'/gi, "");
	
	do_anchor(bbcodetext);
	
	//document.fm.textbox.value = bbcodetext;
	//alert('here');
	
	bbcodetext = bbcodetext.replace(/<BR>/gi, "\r");
	bbcodetext = bbcodetext.replace(/<BR \/>/gi, "\r");
	bbcodetext = bbcodetext.replace(/<P>/gi, "\r\r");
	bbcodetext = bbcodetext.replace(/<P [^>]*>/gi, "\r\r");
	bbcodetext = bbcodetext.replace(/<CODE>/gi, "[code]");
	bbcodetext = bbcodetext.replace(/<\/CODE>/gi, "[/code]");
	bbcodetext = bbcodetext.replace(/<BLOCKQUOTE>/gi, "[quote]");
	bbcodetext = bbcodetext.replace(/<\/BLOCKQUOTE>/gi, "[/quote]");
	bbcodetext = bbcodetext.replace(/<UL[^>]*>/gi, "[list]");
	bbcodetext = bbcodetext.replace(/<\/UL>/gi, "[/list]");
	bbcodetext = bbcodetext.replace(/<OL[^>]*>/gi, "[list=1]");
	bbcodetext = bbcodetext.replace(/<\/OL>/gi, "[/list]");
	bbcodetext = bbcodetext.replace(/<LI>/gi, "[*]");
	//bbcodetext = bbcodetext.replace(/<A HREF=mailto:/gi, "");
	//bbcodetext = bbcodetext.replace(/<A HREF/gi, "[url");
	//bbcodetext = bbcodetext.replace(/<\/A>/gi, "[/url]");

	// *** Jeff!! These two remarked statements are the solution
	// to make a better converter:
	// (.*?) = match any character except new line 0 or more times and remember the match
	// ([\s\S]*?) = match \s any white space char once inclduing \n, \S match any non-white space char, *? any number of times or 0 times
	//bbcodetext = bbcodetext.replace(/<A[\s\S]*?HREF=\"(.*?)\"[\s\S]*?>([\s\S]*?)<\/A>/gi, "[url=$1]$2[\/url]");
	bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)\"[\s\S]*?>/gi, "[img]$1[\/img]");
	bbcodetext = bbcodetext.replace(/<IMG[\s\S]*?SRC=([\s\S]*?)'[\s\S]*?>/gi, "[img]$1[\/img]");
	
	
	//bbcodetext = bbcodetext.replace(/<IMG SRC=/gi, "[img]");
	//bbcodetext = bbcodetext.replace(/.jpg[^>]*>/gi, ".jpg[/img]");
	//bbcodetext = bbcodetext.replace(/.gif[^>]*>/gi, ".gif[/img]");
	//bbcodetext = bbcodetext.replace(/.bmp[^>]*>/gi, ".bmp[/img]");
	//bbcodetext = bbcodetext.replace(/.png[^>]*>/gi, ".png[/img]");
	
	
	bbcodetext = bbcodetext.replace(/<BIG>/gi, "[b]");
	bbcodetext = bbcodetext.replace(/<\/BIG>/gi, "[/b]");
	bbcodetext = bbcodetext.replace(/<B>/gi, "[b]");
	bbcodetext = bbcodetext.replace(/<\/B>/gi, "[/b]");
	bbcodetext = bbcodetext.replace(/<U>/gi, "[u]");
	bbcodetext = bbcodetext.replace(/<\/U>/gi, "[/u]");
	bbcodetext = bbcodetext.replace(/<I>/gi, "[i]");
	bbcodetext = bbcodetext.replace(/<\/I>/gi, "[/i]");
	
	if (codetype == "bbcode")
	{
		bbcodetext = bbcodetext.replace(/<FONT Face[^\'\">]*[\'\">]/gi, "<FONT");
		//bbcodetext = bbcodetext.replace(/<FONT Face[^\']*\'/gi, "<FONT");
		//bbcodetext = bbcodetext.replace(/<FONT Face[^ ]* /gi, "<FONT ");
		//bbcodetext = bbcodetext.replace(/ FACE=[^ ]*\ /gi, " ");
		//bbcodetext = bbcodetext.replace(/ FACE=[^>]*>/gi, ">");
		bbcodetext = bbcodetext.replace(/ FACE=[^\'\"]*[\'\"]/gi, "");
		//bbcodetext = bbcodetext.replace(/ FACE=[^\']*\'/gi, ">");
		
		//alert(bbcodetext);
		//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/size][/color]");
	}  // end if bbcode
	
	if (codetype == "vbcode")
	{
		bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[highlight]");
		bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/highlight]");
		bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code1]");
		bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code1]");
		// <FONT STYLE="background-color:yellow> <-- for hightlighting
		
	}  // end if vbcode
	
	if (codetype == "ipb")
	{
		bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
		bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
		bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code3]");
		bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code3]");
		// <FONT STYLE="background-color:yellow> <-- for hightlighting
		
	}  // end if ipb
	
	if (codetype == "bbcode" || codetype == "vbcode" ||
		codetype == "ipb")
	{	
		bbcodetext = bbcodetext.replace(/<PRE[^>]*>/gi, "[code]");
		bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "[/code]");
		
	}  // end if bbcode or vbcode
	
	if (codetype == "bbcode" || codetype == "smf")
	{
		bbcodetext = bbcodetext.replace(/<TEXTAREA[^>]*>/gi, "[code2]");
		bbcodetext = bbcodetext.replace(/<\/TEXTAREA>/gi, "[/code2]");
	}
	
	if (codetype == "smf" || codetype == "vbcode" ||
		codetype == "ipb")
	{
		bbcodetext = bbcodetext.replace(/<FONT Face/gi, "[font");
		bbcodetext = bbcodetext.replace(/ Face=/gi, "][font=");
		//bbcodetext = bbcodetext.replace(/<\/FONT>/gi, "[/font][/size][/color]");
	
		bbcodetext = bbcodetext.replace(/<LEFT>/gi, "[left]");
		bbcodetext = bbcodetext.replace(/<\/LEFT>/gi, "[/left]");
		bbcodetext = bbcodetext.replace(/<CENTER>/gi, "[center]");
		bbcodetext = bbcodetext.replace(/<\/CENTER>/gi, "[/center]");
		bbcodetext = bbcodetext.replace(/<RIGHT>/gi, "[right]");
		bbcodetext = bbcodetext.replace(/<\/RIGHT>/gi, "[/right]");
	
	} // end if smf or vbcode

	
	if (codetype == "smf")
	{
		// because smf does not have ordered list <OL> support
		bbcodetext = bbcodetext.replace(/\[list=1\]/gi, "[list]");
		bbcodetext = bbcodetext.replace(/<STRONG>/gi, "[glow=red,2,50]");
		bbcodetext = bbcodetext.replace(/<\/STRONG>/gi, "[/glow]");
		bbcodetext = bbcodetext.replace(/<STRIKE>/gi, "[s]");
		bbcodetext = bbcodetext.replace(/<\/STRIKE>/gi, "[/s]");
		bbcodetext = bbcodetext.replace(/<MARQUEE[^>]*>/gi, "[move]");
		bbcodetext = bbcodetext.replace(/<\/MARQUEE>/gi, "[/move]");
		bbcodetext = bbcodetext.replace(/<PRE>/gi, "[pre]");
		bbcodetext = bbcodetext.replace(/<\/PRE>/gi, "[/pre]");
		bbcodetext = bbcodetext.replace(/<HR[^>]*>/gi, "[hr]");
		bbcodetext = bbcodetext.replace(/<object[^>]*width=/gi, "[flash=");
		bbcodetext = bbcodetext.replace(/<object[^>]*height=/gi, "[flash=");
		bbcodetext = bbcodetext.replace(/\" height=/gi, ",");
		bbcodetext = bbcodetext.replace(/\' height=/gi, ",");
		bbcodetext = bbcodetext.replace(/\" width=/gi, ",");
		bbcodetext = bbcodetext.replace(/\' width=/gi, ",");
		bbcodetext = bbcodetext.replace(/ width=/gi, ",");
		bbcodetext = bbcodetext.replace(/ height=/gi, ",");
		bbcodetext = bbcodetext.replace(/\<movie=/gi, "");	
		//bbcodetext = bbcodetext.replace(/<embed src=/gi, "");
		bbcodetext = bbcodetext.replace(/.swf[^>]*>/gi, ".swf[/flash]");
		bbcodetext = bbcodetext.replace(/<TABLE[^>]*>/gi, "[table]");
		bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "[tr]");
		bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, "[td]");
		bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, "[td]");
		bbcodetext = bbcodetext.replace(/<\/TABLE>/gi, "[/table]");
		bbcodetext = bbcodetext.replace(/<\/TR>/gi, "[/tr]");
		bbcodetext = bbcodetext.replace(/<\/TD>/gi, "[/td]");
		bbcodetext = bbcodetext.replace(/<\/TH>/gi, "[/td]");
		bbcodetext = bbcodetext.replace(/<SUP>/gi, "[sup]");
		bbcodetext = bbcodetext.replace(/<\/SUP>/gi, "[/sup]");
		bbcodetext = bbcodetext.replace(/<SUB>/gi, "[sub]");
		bbcodetext = bbcodetext.replace(/<\/SUB>/gi, "[/sub]");
		bbcodetext = bbcodetext.replace(/<TT>/gi, "[tt]");
		bbcodetext = bbcodetext.replace(/<\/TT>/gi, "[/tt]");
		bbcodetext = bbcodetext.replace(/<ABBR TITLE=/gi, "[acronym=");
		bbcodetext = bbcodetext.replace(/<\/ABBR>/gi, "[/acronym]");
		bbcodetext = bbcodetext.replace(/<ACRONYM TITLE=/gi, "[acronym=");
		bbcodetext = bbcodetext.replace(/<\/ACRONYM>/gi, "[/acronym]");
	} // end if smf	
	else
	{
		// table tags for everyone but smf
	
		bbcodetext = bbcodetext.replace(/<TR[^>]*>/gi, "\r");
		bbcodetext = bbcodetext.replace(/<TD[^>]*>/gi, " ");
		bbcodetext = bbcodetext.replace(/<TH[^>]*>/gi, " ");
	
		bbcodetext = bbcodetext.replace(/<\/TR>/gi, " ");
		bbcodetext = bbcodetext.replace(/<\/TD>/gi, " ");
		bbcodetext = bbcodetext.replace(/<\/TH>/gi, " ");
	}		
	// font size and color tags
	bbcodetext = bbcodetext.replace(/<FONT SIZE=/gi, "[size=");
	bbcodetext = bbcodetext.replace(/<FONT color=/gi, "[color=");
	// maybe they put the size and color in one font statement
	// so look for SPACE color and SPACE size
	bbcodetext = bbcodetext.replace(/ color=/gi, "][color=");
	bbcodetext = bbcodetext.replace(/ size=/gi, "][size=");
		
	// The following for loop is for /FONT tags
	// we are removing global search because we have to remove
	// each </FONT> tag one at a time because some are closing
	// [color], [size], or [font]
	var fonttag;
	for (i = 0; fontclose[i].font != 0; i++)
	{
		fonttag = "";
		if (codetype == "smf" || codetype == "vbcode" ||
			codetype == "ipb")
			if (fontclose[i].face == 1)
				fonttag = "[/font]";
		if (fontclose[i].color == 1)
			fonttag = fonttag + "[/color]";
		if (fontclose[i].size == 1)
			fonttag = fonttag + "[/size]";
		
		bbcodetext = bbcodetext.replace(/<\/FONT>/i, fonttag);
	}  // end for
		
	// The following for loop is to search anchor tags
	// to have the right closing for mailto or http.
	// It also does </A> tags
	// we remove the global case in the replace function
	for (i = 0; anchorlist[i].pos != 0; i++)
	{
		if (anchorlist[i].pos == 2)  // if URL
		{
			bbcodetext = bbcodetext.replace(/<A HREF/i, "[url");
			bbcodetext = bbcodetext.replace(/<\/A>/i, "[/url]");
		}  // end if URL
		if (anchorlist[i].pos == 1)  // if mailto:
		{
			if (codetype == "bbcode")
				bbcodetext = bbcodetext.replace(/<A HREF[^<]*<\/A>/i, anchorlist[i].face);	
			else  // if codetype is smf or vbcode
			{
				bbcodetext = bbcodetext.replace(/<A HREF=MAILTO:/i, "[email=");
				bbcodetext = bbcodetext.replace(/<\/A>/i, "[/email]");
			}
		}  // end if mailto:
	}  // end for loop for anchor tags
						
	// This replaces all remaining HTML code between < and >
	//bbcodetext = htmltext.replace(/<&#91;^>&#93;*>/g, "");
	bbcodetext = bbcodetext.replace(/<[^>]*>/g, "");

	// This will convert all > into ] because we left
	// some open up top such as removing <font size
	// and <UL
	bbcodetext = bbcodetext.replace(/>/g, "]");
	bbcodetext = bbcodetext.replace(/\'>/g, "]");
	bbcodetext = bbcodetext.replace(/\">/g, "]");
	bbcodetext = bbcodetext.replace(/\']/g, "]");
	bbcodetext = bbcodetext.replace(/\"]/g, "]");

while (bbcodetext.indexOf("&amp;") != -1) {
	bbcodetext = bbcodetext.replace("&amp;", "&"); }
	
	// The following for loop searches through all textareas.
	// It takes place after all < > tags have been removed
	// because it needs to go back in and put all the data
	// back into the <TEXTAREA></TEXTAREA> tags unchanged.
	// For that we search for [code1] & [code2]
	for (i = 0; textarealist[i].pos != 0; i++)
	{
		if (textarealist[i].pos == 1)  // if TEXTAREA
		{
			//alert("hi");
			// turn textarea to Vb Codes [php] tag
			if (vbcodeoption == "php")
				bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[php]" + textarealist[i].face + "[/php]");
			if (vbcodeoption == "code")
				bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[code]" + textarealist[i].face + "[/code]");
			if (vbcodeoption == "html")
				bbcodetext = bbcodetext.replace(/\[code1\][\w\W]*?\[\/code1\]/i, "[html]" + textarealist[i].face + "[/html]");	
			if (ipbcodeoption == "sql")
				bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[sql]" + textarealist[i].face + "[/sql]");
			if (ipbcodeoption == "code")
				bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[code]" + textarealist[i].face + "[/code]");
			if (ipbcodeoption == "html")
				bbcodetext = bbcodetext.replace(/\[code3\][\w\W]*?\[\/code3\]/i, "[html]" + textarealist[i].face + "[/html]");	
			
			// turn textarea to bbcode & smf [code] tag
			bbcodetext = bbcodetext.replace(/\[code2\][\w\W]*?\[\/code2\]/i, "[code]" + textarealist[i].face + "[/code]");
		}  // end if TEXTAREA
	}  // end for loop for textarea tags
		
	return bbcodetext
		
} // end function convert()
